<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>更新角色</title>
   <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <script src="/static/lib/layui/layui.js"></script>
</head>
<style>

  </style>
<body>
<form class="layui-form">
    <div style="margin-top: 50px">
    <label class="layui-form-label">名称</label>
      <div class="layui-input-block">
        <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" style="width:200px" value="{{ request.session.rolename }}">
      </div>
     <div class="layui-form-item layui-form-text" style="margin-top: 10px">
      <label class="layui-form-label">描述</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" class="layui-textarea"  id="desc"  ></textarea>
      </div>
  </div>
  </div>
  <button class="layui-btn layui-btn-normal"  style="margin-top: 20px; margin-left:65px" id="update_role" type="button">更新角色</button>
  <button class="layui-btn layui-btn-primary layui-border-blue" type="button" style="margin-top: 20px; margin-left:10px" id="cancel">取消</button>
</form>

<script>
    var $;
    var index = parent.layer.getFrameIndex(window.name);
    layui.use(['layer','form'], function(){
         $=layui.jquery;
             $('#cancel').on("click",function(){
            //获取当前窗口的name
                 parent.layer.close(index);//关闭窗口
             });
            $('#update_role').on("click",function(){
                 var role_name = $("#name").val()
                var desc = $("#desc").val()

                $.ajax({
                    url: "/zgh0381/role_doupdate/",  // 请求的地址
                    type: "post",  // 请求方式
                    // 请求时传递过去的数据
                    data:{"role_name": role_name, "desc": desc},
                    dataType: "json",  // 返回的数据格式
                    async: true,  // 异步的ajax
                }).success(function (data) {
                    if(data.res == 1) {
                        layer.confirm('更新成功!', {icon: 1, title: '更新成功'}, function (index) {
                             layer.closeAll();
                        })
                    }
                    else if(data.res == 0){
                        // 请求失败，显示错误信息
                       layer.alert('更新失败!');
                    }

                })






     });



})


</script>

</body>
</html>
